package cn.csdj.sism.web;

import cn.csdj.sism.pojo.Class;
import cn.csdj.sism.pojo.Consultant;
import cn.csdj.sism.service.ConsultantService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 咨询师控制器
 * 夏康
 */
@CrossOrigin
@RestController
@RequestMapping("/consultant")
public class ConsultantController {
    //注入咨询师业务层
    @Autowired
    private ConsultantService consultantService;

    //添加咨询师
    @PostMapping
    public void insert(@RequestBody Consultant consultant){
        if (StringUtils.isEmpty(consultant.getConsultantId())) {
            consultantService.insert(consultant);
        }else {
            consultantService.update(consultant);
        }
    }

    //删除咨询师
    @DeleteMapping("/{id}")
    public int deleteById(@PathVariable Integer id){
        return consultantService.deleteById(id);
    }
    //修改咨询师
    @PutMapping
    public int update(@RequestBody Consultant consultant){
        return consultantService.update(consultant);
    }
    //根据id查询咨询师
    @GetMapping("/{id}")
    public Consultant selectById(@PathVariable Integer id){
        return consultantService.selectById(id);
    }
    //查询所有咨询师
    @GetMapping
    public List<Consultant> selectAll(){
        return consultantService.selectAll();
    }

    @GetMapping("/page/{current}/{pageSize}")
    public IPage<Consultant> selectPage(@PathVariable Integer current, @PathVariable Integer pageSize){
        return consultantService.selectPages(current,pageSize);
    }
}
